<?php
require_once(DP_BASE_DIR."/modules/masterdata/mddivision.class.php");
$div_id = intval( dPgetParam( $_GET, 'div_id', 0 ) );

// check permissions for this record
/*
$perms =& $AppUI->acl();
if (! ($canEdit = $perms->checkModuleItem( 'currencys', 'edit', $currency_id )) ) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}
*/

// load the record data
$msg = '';
$row = new CMdDivision();

$canDelete = $row->canDelete( $msg, $div_id );
if($msg == $AppUI->_('divisionDeleteUserError', UI_OUTPUT_JS)) {
	$userDeleteProtect=true;
}

if ($view) {
	$view = ' readonly="true"';
}
else {
	unset($view);
}

if (!$row->load( $div_id ) && $div_id > 0) {
	$AppUI->setMsg( 'Division' );
	$AppUI->setMsg( 'invalidID', UI_MSG_ERROR, true );
	$AppUI->redirect();
}

$q = new DBQuery();
$q->addTable('divisions');
$q->addQuery('div_code');
if (isset($row->div_code)) {
	$q->addWhere("div_id != $row->div_id");
}
$quoteCodeList = $q->loadColumn();
$qCL = '["' . implode('", "', $quoteCodeList) . '"]';

if (!$view) {
?>
<form name="MdDivisionForm" action="?m=masterdata" method="post">
<input type="hidden" name="dosql" value="mddivision_do_aed" />
<input type="hidden" name="div_id" value="<?=$div_id?>" />
<?}?>
<table border="0" cellpadding="8" cellspacing="0" width="400px">
<tr>
<td colspan="2" bgcolor="#E0E0E0"><b><?=$AppUI->_('Division Information')?></td>
</tr>
<tr>
	<td colspan="2">
		<table border="0" cellpadding="0" cellspacing="4" width="100%">
		<tr>
			<td align="right"> * <?=$AppUI->_('Code')?></td>
			<td colspan="3">
				<input ftype=""  type="text" class="text" name="div_code" id="div_code"
				value="<?=@$row->div_code?>" maxlength="20" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right"> * <?=$AppUI->_('Name')?></td>
			<td colspan="3">
				<input type="text" class="text" name="div_name" id="div_name"
					value="<?=@$row->div_name?>" maxlength="150" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right"><?=$AppUI->_('Address')?></td>
			<td colspan="3">
				<input type="text" class="text" name="div_address" id="div_address"
					value="<?=@$row->div_address?>" maxlength="255" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right"><?=$AppUI->_('Tel')?></td>
			<td>
				<input type="text" class="text" name="div_tel" id="div_tel"
					value="<?=@$row->div_tel?>" maxlength="16" style="width: 130px" <?=$view?>/>
			</td>
			<td align="right"><?=$AppUI->_('Fax')?></td>
			<td>
				<input type="text" class="text" name="div_fax" id="div_fax"
					value="<?=@$row->div_fax?>" maxlength="16" style="width: 130px" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right"><?=$AppUI->_('Active')?></td>
			<td><input type="checkbox" name="div_active"
					value="<?=@$row->div_active?>"  <?=$view?> <?= (@$row->div_active == 1) ? "checked":""?>/>
			</td>
		</tr>
		</table>
	</td>
</tr>
<tr>
	<td align="center" colspan="2" style="border-top: 1px solid #E0E0E0">
	<? if (!$view) { ?>
		<input type="submit" class="button" value="<?=$AppUI->_('Save')?>"/>
		<input type="button" class="button" value="<?=$AppUI->_('Cancel')?>" onClick="doCloseDivision()"/>
	<? } else { ?>
		<input type="button" class="button" value="<?=$AppUI->_('Close')?>" onClick="doCloseDivision()"/>
	<? } ?>
	</td>
</tr>
</table>
</form>
<div id="validation_rules" style="visibility: hidden; display: none">
	var fDivCode = new LiveValidation('div_code');
	fDivCode.add( Validate.Presence );
	fDivCode.add( Validate.Exclusion , {within: <?=$qCL?>});

	var fDivName = new LiveValidation('div_name');
	fDivName.add( Validate.Presence );


	new Tips($$('.text'));
</div>
<script language="JavaScript" type="text/javascript">
	eval($('validation_rules').innerHTML);
</script>
